<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<text slot="content" @click="selectDrawer">
				{{title}}
			</text>
			<text slot="right" style="margin-right: 15px;" @click="selectDrawer">选择</text>
		</cu-custom>
		<view style="color:red">
			学期列表 使用接口 /api/v1/semester/findSemesterList
			<br>
			考试列表 使用接口 /api/v1/achievement/selectAchievements
			<br>
			考试列表 没有学期筛选字段
			<br>
			没有成绩详情接口
		</view>
		<a-scroll :request="get" ref="aScroll" :parm="parm">
			<template #item="{row:x,index}">
				<a-list :value="x" :url="`./Grades?id=${x.id}`"></a-list>
			</template>
		</a-scroll>
		<uni-drawer ref="drawer" mode="right" :width="300">
			<view class="filter-list" v-for="x in semester" @click="clickFilter(x)">
				{{x.title}}
			</view>
		</uni-drawer>
	</view>
</template>

<script>
	import {
		format
	} from "@/common/js/utils";
	export default {
		//上拉触底
		onReachBottom() {
			this.$refs.aScroll.lower();
		},
		//下拉刷新
		onPullDownRefresh() {
			this.$refs.aScroll.get(true).then(res => {
				uni.stopPullDownRefresh();
			});
		},
		onLoad() {
			//查询学期
			this.$http.post('/api/v1/semester/findSemesterList').then(res=>{
				this.semester = res.map(x=>{
					return {
						...x,
						title:`${format(x.startTime,'yyyy-MM')}至${format(x.endTime,'yyyy-MM')} ${x.name}`
					}
				});
				this.clickFilter(this.semester[0]);
			});
		},
		data() {
			return {
				title: '',
				parm:{
					semesterId:''
				},
				semester:[]
			}
		},
		methods: {
			selectDrawer() {
				this.$refs.drawer.open();
			},
			clickFilter(e) {
				this.title = e.title;
				this.parm.semesterId = e.id;
				this.$refs.drawer.close();
				this.$refs.aScroll.get(true)
			},
			get(parm = {}) {
				return this.$http.post('/api/v1/achievement/selectAchievements', {
					...parm
				}).then(res => {
					return {
						total: res.totalSize,
						data: res.results.map(x => {
							return {
								...x,
								name:`${x.termName} ${x.examName}`,
								sonTitle: format(x.examDate),
								img: require('./2.png')
							}
						})
					}
				});

				const data = new Array(15).fill({
					name: "2020-2021 第一学期 其中考试",
					sonTitle: "2020-11-21",
					img: require('./2.png'),
					url(e) {
						return '/pages/parents/TestScore/Grades';
					}
				});
				console.log('请求：' + JSON.stringify({
					...parm,
					title: this.title
				}));
				return new Promise(r => {
					setTimeout(e => {
						r({
							total: 200,
							data
						})
					}, 1000);
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #fff;
	}

	.filter-list {
		padding: 10px;
		text-align: center;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		border-bottom: 1px solid rgba(0, 0, 0, .1);
	}
</style>
